import type { ArticleItem } from '~/apis/article/model'
import type { BlogPost } from '~/types'

export function transformPost(article: ArticleItem, p?: Omit<BlogPost, '_id' | 'body'>): BlogPost {
  const post = {
    ...p,
    _id: p?._id ?? String(article.id),
    body: p?.body,
    _path: `/article/detail/${article.id}`,
    title: article.title,
    description: article.desc,
    date: article.createTime,
    badge: {
      label: article.typeName
    },
    authors: [
      {
        name: article.authorName || 'L',
        description: '',
        avatar: {
          src: article.authorAvatar
        },
        label: '',
        to: 'https://gitee.com/lginsane'
      }
    ]
  }
  return post
}
